//
//  MyEmotionBtn.m
//  WeChat
//
//  Created by ibokan on 16/2/20.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "YJEmotionBtn.h"
#import "YJEmotion.h"
#import "NSString+Emoji.h"
@implementation YJEmotionBtn
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setting];
    }
    return self;
}

//从XIB初始化时
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        [self setting];
    }
    return self;
}

- (void)setting
{
    self.adjustsImageWhenHighlighted = NO;
    self.titleLabel.font = [UIFont systemFontOfSize:39.0f];
    self.backgroundColor = [UIColor clearColor];
}

-(void)setEmotion:(YJEmotion *)emotion
{
    _emotion = emotion;
    
    //这种方法，名字一定要全，包括@2x都不能省略
    //        NSString *path = [[NSBundle mainBundle]pathForResource:@"default/d_baibai@2x.png"ofType:nil];
    //        UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    if (emotion.png)
    {
        NSString *imageStr = [NSString stringWithFormat:@"default/%@",emotion.png];
         UIImage *image = [UIImage imageNamed:imageStr];
         [self setImage:image forState:UIControlStateNormal];
        //清楚emoji表情，针对popView中放大镜的表情
        [self setTitle:nil forState:UIControlStateNormal];
    }else if(emotion.code)
    {
        //emotion.code.emoji ----> [emotion.code emoji]等价  16进制编码转字符串
        [self setTitle:emotion.code.emoji forState:UIControlStateNormal];
        //清楚自定义表情
        [self setImage:nil forState:UIControlStateNormal];
    }
    
}
@end
